<template>
  <!-- 首页 -->
  <div class="home">
    <van-search
      v-model="searchvalue"
      placeholder="请输入搜索关键词"
      disabled
      shape="round"
      @click="$router.push('/home/searchPopup')"
    />
    <!-- 轮播图 -->
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="skyblue">
      <van-swipe-item v-for="item in banner" :key="item.id"
        ><img
          :src="item.image_url"
          alt=""
          width="100%"
          :style="{ display: 'block' }"
      /></van-swipe-item>
    </van-swipe>
    <!-- 图标宫格 -->
    <van-grid :column-num="5">
      <van-grid-item
        v-for="item in channel"
        :key="item.id"
        :icon="item.icon_url"
        :text="item.name"
      />
    </van-grid>
    <div class="brand">
      <p class="s-title">品牌制造商直供</p>
      <ul>
        <li v-for="item in brandList" :key="item.id">
          <img :src="item.pic_url" alt="" width="100%" />
          <h4>{{ item.name }}</h4>
          <p>{{ item.floor_price | RMB }}</p>
        </li>
      </ul>
    </div>
    <!-- 新品 -->
    <div class="newgood">
      <p class="s-title">周一周四·新品首发</p>
      <van-grid :border="false" :column-num="2">
        <van-grid-item v-for="item in newGoodsList" :key="item.id">
          <van-image :src="item.list_pic_url" />
          <p>{{ item.name }}</p>
          <p class="ng_price" :style="{ color: 'brown' }">
            {{ item.retail_price | RMB }}
          </p>
        </van-grid-item>
      </van-grid>
    </div>
    <!-- 人气推荐 -->
    <div class="hotgood">
      <p class="s-title">人气推荐</p>
      <van-card
        :price="item.retail_price | RMB2"
        :desc="item.goods_brief"
        :title="item.name"
        :thumb="item.list_pic_url"
        v-for="item in hotGoodsList"
        :key="item.id"
      />
    </div>
    <!-- 专题精选 -->
    <div class="b_topic">
      <p class="s-title">专题精选</p>
      <div class="topic">
        <van-swipe :loop="false" :width="300" :show-indicators="false">
          <van-swipe-item v-for="item in topicList" :key="item.id">
            <img :src="item.scene_pic_url" alt="" width="100%" height="200px" />
            <div>
              <h4>{{ item.title }}</h4>
              <span>{{ item.price_info | RMB }}起</span>
            </div>
            <p>{{ item.subtitle }}</p>
          </van-swipe-item>
        </van-swipe>
      </div>
    </div>
    <!-- 分类 -->
    <div>
      <ul>
        <li
          class="newgood cgl"
          v-for="(item, index) in categoryList"
          :key="index"
        >
          <p class="s-title">{{ item.name }}</p>
          <van-grid :border="false" :column-num="2">
            <van-grid-item v-for="e in item.goodsList" :key="e.id">
              <van-image :src="e.list_pic_url" />
              <p class="cg_name">{{ e.name }}</p>
              <p class="ng_price" :style="{ color: 'brown' }">
                {{ e.retail_price | RMB }}
              </p>
            </van-grid-item>
          </van-grid>
        </li>
      </ul>
    </div>

    <!-- <transition name="van-slide-right">
      <router-view></router-view>
    </transition> -->

    <transition name="rightslide">
      <router-view></router-view>
    </transition>
  </div>
</template>

<script>
// @ is an alias to /src
// import HelloWorld from '@/components/HelloWorld.vue'
// import axios from "axios";
import { GetHomeData } from "@/request/api";
export default {
  name: "Home",
  data() {
    return {
      searchvalue: "", // 搜索框的v-model值
      banner: [],
      channel: [],
      brandList: [],
      newGoodsList: [],
      hotGoodsList: [],
      topicList: [],
      categoryList: [],
    };
  },
  created() {
    GetHomeData()
      .then((res) => {
        // 请求成功之后执行
        // console.log(res.data);
        this.banner = res.data.banner;
        this.channel = res.data.channel;
        this.brandList = res.data.brandList;
        this.newGoodsList = res.data.newGoodsList;
        this.hotGoodsList = res.data.hotGoodsList;
        this.topicList = res.data.topicList;
        this.categoryList = res.data.categoryList;
      })
      .catch((err) => {
        // 请求失败之后执行
        console.log(err);
      });
  },
  components: {},
  filters: {
    RMB(val) {
      return "￥" + val.toFixed(2) + "元";
    },
    RMB2(val) {
      return val.toFixed(2);
    },
  },
};
</script>

<style lang="less" scoped>
.s-title {
  line-height: 50px;
  height: 50px;
  text-align: center;
}
.brand {
  margin-top: 20px;
  width: 100%;
  height: 100%;
  background-color: #fff;
  ul {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    li {
      position: relative;
      width: 49%;
      img {
        width: 100%;
      }
      h4,
      p {
        position: absolute;
        left: 10px;
        top: 10px;
      }
      p {
        font-size: .16rem;
        top: 40px;
        color: brown;
      }
    }
  }
}
.newgood {
  background-color: #fff;
  margin-top: 20px;
  p {
    display: block;
    line-height: 30px;
    height: 30px;
    width: 100%;
    text-align: center;
  }
  .s-title {
    line-height: 50px;
    height: 50px;
    text-align: center;
  }
}
.hotgood {
  margin-top: 20px;
  background-color: #fff;
  .van-card__title {
    font-size: 16px;
  }
  .van-card__desc {
    line-height: 40px;
    height: 40px;
    max-height: 100px;
  }
  .van-card__bottom {
    span {
      color: brown;
    }
  }
}
.b_topic {
  background-color: #fff;
  margin-top: 20px;
  .topic {
    padding: 4px;
    h4,
    span {
      float: left;
      height: 40px;
      line-height: 40px;
      font-size: 0.16rem;
    }
    span {
      color: brown;
    }
    p {
      float: left;
      text-overflow: ellipsis;
      white-space: nowrap;
      overflow: hidden;
      width: 100%;
    }
  }
}
.cgl {
  .cg_name {
    overflow: hidden;
    text-overflow: ellipsis;
    // white-space: nowrap;
  }
}

.rightslide-enter,
.rightslide-leave-to {
  right: -100%;
}
.rightslide-enter-active,
.rightslide-leave-active {
  transition: right 0.5s;
}
.rightslide-enter-to,
.rightslide-leave {
  right: 0;
}
</style>
